package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.uitils.QiniuUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    //@Test
    public void clearImg(){
        Jedis resource = jedisPool.getResource();
        Set<String> set = resource.sdiff(RedisConstant.SETMEAL_PIC_RESOURCE, RedisConstant.SETMEAL_PIC_DBRESOURCE);
        if(set != null){
            for (String picName : set) {
                //输出七牛云服务器上的图片
                QiniuUtils.deleteFileFromQiniu(picName);
                //在Redis集合中删除图片名称
                resource.srem(RedisConstant.SETMEAL_PIC_RESOURCE,picName);
            }
        }
        //Redis集合中的数据在存储到mysql和上传至七牛云后无用，所以可以定期全删
       // jedisPool.getResource().del(RedisConstant.SETMEAL_PIC_DBRESOURCE,RedisConstant.SETMEAL_PIC_RESOURCE);
        resource.close();

    }
}

